package gases.as3.librarys.components.ui.basic
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	
	import gases.as3.librarys.components.ui.GUIComponents;
	
	/**
	 * 图片盒子
	 * @author gases
	 * 
	 */
	public class GImageBox extends GUIComponents
	{
		public function GImageBox()
		{
		}
		
		override protected function initialization():void
		{
			super.initialization();
			if(!_imageBmp)
			{
				_imageBmp = new Bitmap();
				this.addChild(_imageBmp);
			}
		}
		
		public function set source(value:Object):void
		{
			_source = value;
			resloveSource();
		}
		
		public function get source():Object
		{
			return _source;
		}
		
		private function changeBmd(bmd:BitmapData):void
		{
			_imageBmp.bitmapData = bmd;
			setWH();
		}
		
		private function resloveSource():void
		{
			if(_source is BitmapData)
			{
				var bmd:BitmapData = _source as BitmapData;
				changeBmd(bmd);
				return;
			}
			if(_source is Bitmap)
			{
				var bmp:Bitmap = _source as Bitmap;
				changeBmd(bmp.bitmapData);
				return;
			}
			if(_source is String)
			{
				trace("需要去加载");
				return;
			}
		}
		
		private function setWH():void
		{
			_imageBmp.width = Gwidth;
			_imageBmp.height = Gheight;
		}
		
		
		override public function dispose():void
		{
			if(_imageBmp)
			{
				this.removeChild(_imageBmp);
				if(_imageBmp.bitmapData)
				{
					_imageBmp.bitmapData = null;
				}
				_imageBmp = null;
			}
			super.dispose();
		}
		
		private var _source:Object;
		private var _imageBmp:Bitmap;
		private var _isAutoLayout:Boolean;// 是否当图片设置完后按照图片的大小自动布局,暂时无用
	}
}


